Preventing Sleep on Computers
Written: | 2025-08-19 |
Tags: | #snippet #how-to |
Instead of working through OS settings that often don't work, there's a simple solution to preventing your system from going to sleep: generating user input.
Here's a simple script that uses pyautogui to press the shift key every 5 minutes:
import pyautogui
import time
while True:
time.sleep(5 * 60)
pyautogui.press("shift")
print("pressed shift")